import Request from '@/utils/request'
import Cookies from '@/utils/auth'

const state = () => ({
	detail: {},
	detailType:1,  // 详情类型：1为藏品详情，2为拍卖详情
	userInfo:JSON.parse(Cookies.get('userInfo') || '{}'),
	useAdress:{},  // 使用地址
	backUrl:'',  // 返回地址
	statusBarHeight:Cookies.get('statusBarHeight'),  // 手机状态栏的高度
	currentPosition:{} // 当前位置信息
})
const getters = {
	detailType(state) {
		return state.detailType;
	}
}
const mutations = {
	set_detail: (state, data) => {
		state.detail = data
	},
	set_detailType: (state, data) => {
		state.detailType = data
	},
	set_userInfo: (state, data) => {
		Cookies.set('userInfo',JSON.stringify(data))
		state.userInfo = data
	},
	set_useAdress: (state, data) => {
		state.useAdress = data
	},
	set_backUrl: (state, data) => {
		state.backUrl = data
	},
	set_statusBarHeight: (state, data) => {
		Cookies.set('statusBarHeight',data)
		state.statusBarHeight = data
	},
	set_currentPosition: (state, data) => {
		state.currentPosition = data
	},
}
const actions = {
	async getArtist({commit}, params) {   // 艺术家列表
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/artist/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_collection_list({commit}, params) {   // 藏品列表
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/goods/collection/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_auction_list({commit}, params) {   // 拍卖会列表
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/goods/auction/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_goods_detail({commit}, params) {   // 藏品详情
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/goods/collection/detail',params)
			.then(res=>{
				if(res.data.success){
					commit('set_detail',res.data.data)
				}
				resolve(res.data) 
			})
		})
	},
	async get_auction_goods_detail({commit}, params) {   // 拍卖详情
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/goods/auction/detail',params)
			.then(res=>{
				if(res.data.success){
					commit('set_detail',res.data.data)
				}
				resolve(res.data) 
			})
		})
	},
	async get_arlandmark_list({commit}, params) {   // 获取AR地标列表
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/ar/arlandmark/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_arlandmark_detail({commit}, params) {   // AR地标详情
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/ar/arlandmark/detail',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_artist_detail({commit}, params) {   // 艺术家详情
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/artist/detail',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async artist_collection_list({commit}, params) {   // 艺术家寄售作品
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/goods/artist/collection/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async artist_auction_list({commit}, params) {   // 艺术家拍卖作品
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/goods/artist/auction/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async artist_follow_list({commit}, params) {   // 我关注的艺术家
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/artist/myList',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_userInfo({commit}, params) {   // 获取用户信息
		return new Promise((resolve,reject)=>{
			Request.get('/mobile/user/my/personalCenter',params)
			.then(res=>{
				if(res.data.success){
					commit('set_userInfo',res.data.data)
				}
				resolve(res.data) 
			})
		})
	},
	async upload_bg_img({commit}, params) {  
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/user/my/personalCenter/setBackgroundUrl',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async upload_head_img({commit}, params) {  
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/user/my/personalCenter/setHeadUrl',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async set_goods_live({commit}, params) {   // 喜欢商品
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/goods/attention',params,{unLoading:true})
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async cancel_goods_live({commit}, params) {   // 取消喜欢
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/goods/attention/cancel',params,{unLoading:true})
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async live_goods_list({commit}, params) {   // 商品喜欢列表
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/goods/attention/collection/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_meet_ar({commit}, params) {   // 艺术遇见AR列表
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/ar/arArtist/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_meet_ar_detail({commit}, params) {   // 艺术遇见AR详情
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/ar/arArtist/detail',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async upload_file({commit}, fromData) {   // 上传文件，fromData文件流数据
		return new Promise((resolve,reject)=>{
			let config = {
				headers: {
					'Content-Type': 'multipart/form-data'
				}
			}
			Request.post('/resource/fileupload/upload',fromData,config)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async add_follow({commit}, params) {   // 添加关注
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/artist/attention',params,{unLoading:true})
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async cancel_follow({commit}, params) {   // 取消关注
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/artist/attention/cancel',params,{unLoading:true})
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_cash_balance({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.get('/api/user/cashCoupon/balance',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async redpacket_record({commit}, params) {   
		return new Promise((resolve,reject)=>{
			Request.post('/api/user/cashCoupon/findList',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_integral({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.get('/api/user/points/balance',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async integral_record({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.post('/api/user/points/findList',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async offer({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.post('/api/mall/bidOrder/create',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async add_address({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.post('/api/mall/address/add',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_address_list({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.get('/api/mall/address/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_address_detail({commit}, addressId) { 
		return new Promise((resolve,reject)=>{
			Request.get(`/api/mall/address/get/${addressId}`)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async edit_address({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.post('/api/mall/address/edit',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_latest_address({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.get('/api/mall/address/latest',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async my_jion_auction({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.post('/api/user/bidOrder/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async my_jion_auction_detail({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.post('/api/user/bidOrder/bidResult',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_freight({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.post('/api/mall/order/getFreightAmount',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async direct_buy_creade_order({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.post('/api/mall/order/create',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async creade_pay_order({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.post('/api/mall/order/createPayInfo',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async auction_record({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.post('/api/mall/bidOrder/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_my_order({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.post('/api/mall/order/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_my_order_detail({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.post('/api/mall/order/detail',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_sys_msg_list({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/consumer/system/message/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_notice_list({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/common/system/bulletin/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_notice_detail({commit}, bulletinId) { 
		return new Promise((resolve,reject)=>{
			Request.post(`/mobile/common/system/bulletin/getDetail/${bulletinId}`)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async ar_auction_list({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/goods/arlandmark/auction/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async ar_collection_list({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/goods/arlandmark/collection/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_article_list({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.post('/api/articles-api/articles-list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_edition_list({commit}, os_type) { //osType=0:android, osType==1:ios
		return new Promise((resolve,reject)=>{
			Request.get(`/api/version/get/list/${os_type}`)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_ar_provinceData({commit}, params) { 
		return new Promise((resolve,reject)=>{
			Request.get('/mobile/ar/provinceArStatistics',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async update_nick({commit}, params) {  
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/user/my/personalCenter/setNick',params,{unLoading:true})
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async signOut({commit}, os_type) { // 退出登录
		// Cookies.remove('token')
		// location.href = '/h5/login'
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/user/my/personalCenter/quit')
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async destroy_user({commit}, os_type) { // 注销用户
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/user/my/personalCenter/cancel')
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_goods_category({commit}, params) { // 分类
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/common/goods/category/list')
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_my_goods({commit}, params) { // 我的藏品
		return new Promise((resolve,reject)=>{
			Request.post('/api/mall/order/my/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_order_goods_category({commit}, params) { // 分类
		return new Promise((resolve,reject)=>{
			Request.post('/api/mall/order/my/category/list')
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
}

export default {
	namespaced: true,
	state,
	getters,
	mutations,
	actions
}
